// JavaScript Document

//输入框点击变空
function loginpt(foo){
	var sex = document.getElementsByName(foo)[0];
	sex.style.color = "#333";
	sex.value = '';
}

function locking(){
	document.getElementById('mask').style.display = 'block';
	document.getElementById('popup').style.display='block';
}
function Lock_CheckForm(theForm){
	document.getElementById('mask').style.display='none';
	document.getElementById('popup').style.display='none';
	return false;
}
function inv1(){
	document.getElementById('invi').style.display = "";
}
function inv2(){
	document.getElementById('invi').style.display = "none";
}
function yanzheng(){
	var ym = document.getElementById('yminput').value;
	if(ym == ""){
		document.getElementById('ymicon').className = "sp3 spr";
		document.getElementById('ymcon').innerHTML = "不能为空";
	}else{
		document.getElementById('ymicon').className = "sp3";
		document.getElementById('ymcon').innerHTML = "请输入你收到的6位验证码";
	}
}

function change(){
	var chv = document.getElementById("Merchant").value
	if(chv == "1"){
		document.getElementById('splb').style.display = "inline";
		document.getElementById('splb2').style.display = "none";
	}else if(chv = "2"){
		document.getElementById('splb').style.display = "none";
		document.getElementById('splb2').style.display = "inline";
	}
}

function loginpt(foo,too){
	var sex = document.getElementsByName(foo)[0];
	sex.style.color = "#333";
	sex.value = '';
}


function xiala(){
	var uln = document.getElementById('sear_more');
	var lin = uln.getElementsByTagName('li');
	uln.className = "sear_more searul";
	for(var i = 1,len = lin.length; i < len ; i++){
		lin[i].style.display = "block";
		lin[i].onclick = anla;
	}
}
function ulout(){
	var uln = document.getElementById('sear_more');
	uln.className = "sear_more";
}
function anla(){
	var uln = document.getElementById('sear_more');
	var lin = uln.getElementsByTagName('li');
	var fri = document.getElementById('firli');
	uln.className = "sear_more";
	fri.innerHTML = this.innerHTML;
}



//表格排序
function sortTable(id, col, rev , ths){
	
	var tblEl = document.getElementById(id);

	var rkhd = document.getElementById('rankhd');
	var rkhdsp = rkhd.getElementsByTagName('span');

	for(var i = 0,len = rkhdsp.length;i<len;i++){
		if(i == col - 2){
			if(ths.className == 'sort sortup'){
				ths.className = "sort sortdown";
			}else{
				ths.className = "sort sortup";
			}
		}else{
			rkhdsp[i].className = "sort";
		}
	}
	
	
	if(tblEl.reverseSort == null){
		tblEl.reverseSort = new Array();
		tblEl.lastColumn = 1;
	}

	if(tblEl.reverseSort[col] == null)
		tblEl.reverseSort[col] = rev;

	if(col == tblEl.lastColumn)
		tblEl.reverseSort[col] = !tblEl.reverseSort[col];
		tblEl.lastColumn = col;
		var oldDsply = tblEl.style.display;
		tblEl.style.display = "none";
		var tmpEl;
		var i, j;
		var minVal, minIdx;
		var testVal;
		var cmp;

	for(i = 0; i < tblEl.rows.length - 1; i++){
		minIdx = i;
		minVal = getTextValue(tblEl.rows[i].cells[col]);

		for(j = i + 1; j < tblEl.rows.length; j++){

			testVal = getTextValue(tblEl.rows[j].cells[col]);
			cmp = compareValues(minVal, testVal);

			if(tblEl.reverseSort[col])
				cmp = -cmp;
			if (cmp == 0  &&  col != 1)
				cmp = compareValues(
					getTextValue(tblEl.rows[minIdx].cells[1]),
					getTextValue(tblEl.rows[j].cells[1])
				);
			if(cmp > 0){
				minIdx = j;
				minVal = testVal;
			}
		}

		if(minIdx > i){
			tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
			tblEl.insertBefore(tmpEl, tblEl.rows[i]);
		}

	}

	makePretty(tblEl, col);
	setRanks(tblEl, col, rev);
	tblEl.style.display = oldDsply;
	return false;
}

if(document.ELEMENT_NODE == null){
	document.ELEMENT_NODE = 1;
	document.TEXT_NODE = 3;
}

function getTextValue(el){
	var i;
	var s;
	s = "";
	for(i = 0; i < el.childNodes.length; i++)
	if(el.childNodes[i].nodeType == document.TEXT_NODE)
		s += el.childNodes[i].nodeValue;
	else if (el.childNodes[i].nodeType == document.ELEMENT_NODE && el.childNodes[i].tagName == "BR")
		s += " ";
	else s += getTextValue(el.childNodes[i]);
	return normalizeString(s);
}

function compareValues(v1, v2){
	var f1, f2;
	f1 = parseFloat(v1);
	f2 = parseFloat(v2);
	if(!isNaN(f1) && !isNaN(f2)){
		v1 = f1;
		v2 = f2;
	}
	if(v1 == v2)
		return 0;
	if(v1 > v2)
		return 1
		return -1;
}

var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

function normalizeString(s){
	s = s.replace(whtSpMult, " ");
	s = s.replace(whtSpEnds, "");
	return s;
}

var rowClsNm = "alternaterow";
var colClsNm = "sortedcolumn";
var rowTest = new RegExp(rowClsNm, "gi");
var colTest = new RegExp(colClsNm, "gi");

function makePretty(tblEl, col){
	var i, j;
	var rowEl, cellEl;
	for(i = 0; i < tblEl.rows.length; i++){
		rowEl = tblEl.rows[i];
		rowEl.className = rowEl.className.replace(rowTest, "");
		if(i % 2 != 0)
		rowEl.className += " " + rowClsNm;
		rowEl.className = normalizeString(rowEl.className);
	for (j = 2; j < tblEl.rows[i].cells.length; j++){
		cellEl = rowEl.cells[j];
		cellEl.className = cellEl.className.replace(colTest, "");
		if (j == col)
		cellEl.className += " " + colClsNm;
		cellEl.className = normalizeString(cellEl.className);
	}
}

var el = tblEl.parentNode.tHead;
rowEl = el.rows[el.rows.length - 1];

for(i = 2; i < rowEl.cells.length; i++){
	cellEl = rowEl.cells[i];
	cellEl.className = cellEl.className.replace(colTest, "");
	if(i == col)
		cellEl.className += " " + colClsNm;
		cellEl.className = normalizeString(cellEl.className);
	}
}

function setRanks(tblEl, col, rev){
	var i = 0;
	var incr = 1;
	if(tblEl.reverseSort[col])
	rev = !rev;
	if(rev){
		incr = -1;
		i = tblEl.rows.length - 1;
	}
	var count = 1;
	var rank = count;
	var curVal;
	var lastVal = null;

	while(col > 1  &&  i >= 0  &&  i < tblEl.rows.length){
		curVal = getTextValue(tblEl.rows[i].cells[col]);
		if(lastVal != null  &&  compareValues(curVal, lastVal) != 0)
		rank = count;
		//tblEl.rows[i].rank = rank;
		tblEl.rows[i].rank = count;
		lastVal = curVal;
		count++;
		i += incr;
	}

	var rowEl, cellEl;
	var lastRank = 0;
	for(i = 0; i < tblEl.rows.length; i++){
		rowEl = tblEl.rows[i];
		cellEl = rowEl.cells[0];
		while(cellEl.lastChild != null)
		cellEl.removeChild(cellEl.lastChild);
		if(col > 1  &&  rowEl.rank != lastRank){
			cellEl.appendChild(document.createTextNode(rowEl.rank));
			lastRank = rowEl.rank;
		}
	}
}
//表格排序END
/*套餐充值js*/
function yues(ths){
	var yucln = ths.className;
	if(yucln == "yujbtn onyuj"){
		document.getElementById('yufz').style.display = "none";
		ths.className = "yujbtn";
	}else{
		locking();
	}
}
function kong(){
	var pkv = document.getElementById('pkpopit').value;
	//alert(pkv);
	if(parseInt(pkv)!=pkv || pkv <= 0){
		document.getElementById('poplight').style.display = 'inline';
		return false;
	}else{
		document.getElementById('poplight').style.display = 'none';
	}
}
function Lock_ok(){
	var pkv = document.getElementById('pkpopit').value;
	if(parseInt(pkv)!=pkv || pkv <= 0){
		document.getElementById('poplight').style.display = 'inline';
		return false;
	}else{
		document.getElementById('poplight').style.display = 'none';
	}
	Lock_CheckForm();
	document.getElementById('yufz').style.display = "inline-block";
	document.getElementById('yuj').className = "yujbtn onyuj";
	document.getElementById('monnum').innerHTML = pkv;
}
function taocan(tid){//套餐选择
	var taid = document.getElementById('packtab');
	var rdn = document.getElementsByName('packrd');
	var rdlen = rdn.length;
	var trn = taid.getElementsByTagName('tr');
	var len = trn.length
	//alert(rdlen);
	for(var i = 1;i<len;i++){
		//alert(len);
		if(i == tid){
			trn[i].className = "acctr";
			rdn[i-1].checked = "checked";
		}else{
			trn[i].className = "";
			rdn[i-1].checked = "";
		}
	}
	
	var taoc = document.getElementById("taoid" + tid).innerHTML;
	var taojia = document.getElementById("taojia" + tid).innerHTML;
	document.getElementById('tstaoc').innerHTML = taoc;
	document.getElementById('spittao').value =  taojia;
	document.getElementById('tstaojia').innerHTML = taojia;
}
function keyczm(){
	document.getElementById('tstaojia').innerHTML = document.getElementById('spittao').value;
}


window.onload = init;
function init(){
	if(document.getElementById('popup')){
		var popid = document.getElementById('popup');
		var links = popid.getElementsByTagName("a");

		for(var i = 0, len = links.length;i<len;i++){
			if(links[i].getAttribute("class") == "up"){
				links[i].onclick = function(){
					var pkpval = document.getElementById('pkpopit').value;
					document.getElementById('pkpopit').value = parseInt(pkpval) + 1;
					return false;
				}
			}else if(links[i].getAttribute("class") == "down"){
				links[i].onclick = function(){
					var pkpval = document.getElementById('pkpopit').value;
					document.getElementById('pkpopit').value = parseInt(pkpval) - 1;
					return false;
				}
			}
		}
	}
}